package 每日一题;

import java.util.Arrays;
import java.util.List;

public class 最小时间差 {
    public int findMinDifference(List<String> timePoints) {
        int[] arr = new int[timePoints.size()];
        //转换成分钟数
        for (int i = 0; i < arr.length; i++) {
            arr[i] = Integer.parseInt(timePoints.get(i).substring(0, 2)) * 60 + Integer.parseInt(timePoints.get(i).substring(3));
        }
        Arrays.sort(arr);
        int min = Integer.MAX_VALUE;
        for (int i = 1; i < arr.length; i++) {
            min = Math.min(min, arr[i] - arr[i - 1]);
        }
        //最小的可能是第二天的时间，所以加上 24*60。
        return Math.min(min, arr[0] + 1440 - arr[arr.length - 1]);
    }
}
